import java.util.HashMap;
import java.util.Map;

public class TwoSum {
    // leetcode hot 100 两数之和
    // https://leetcode.cn/problems/two-sum/description/?envType=study-plan-v2&envId=top-100-liked
    public int[] twoSum(int[] nums, int target) {
        Map<Integer,Integer> hash = new HashMap<>();
        int[] ret = new int[2];
        for (int i = 0; i < nums.length; i++) {
            Integer index = hash.get(nums[i]);
            if (index != null) {
                ret[0] = index;
                ret[1] = i;
                return ret;
            }
            hash.put(target-nums[i],i);
        }
        return ret;
    }
}
